/**
 * This class is designed to be used in both website and android.
 * <p/>
 * zhaoxu @ 2012-05-16 10:20
 * <p/>
 */
package com.threeti.mecool.core.domain.model.plan.pojo;

import org.codehaus.jackson.annotate.JsonIgnore;

public class Task {
	private Long id;
	private Integer version;
	private Integer actionId;
	private transient String actionText;
	private Integer dataTypeId;
	private transient String dataTypeText;
	private String text;
	private transient TaskAction action;
	
	public void setAction(TaskAction val) {
		action = val;
		actionId = action.getId();
		actionText = action.getText();
	}

	@JsonIgnore
	public TaskAction getAction() {
		if (action == null) {
			action = TaskAction.from(actionId);
		}
		return action;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public Integer getDataTypeId() {
		return dataTypeId;
	}

	public void setDataTypeId(Integer dataTypeId) {
		this.dataTypeId = dataTypeId;
	}

	public String getDataTypeText() {
		return dataTypeText;
	}

	void setDataTypeText(String dataTypeText) {
		this.dataTypeText = dataTypeText;
	}

	public void setActionText(String actionText) {
		this.actionText = actionText;
	}

	@JsonIgnore
	public String getActionText() {
		if (actionText == null && actionId != null) {
			if (action == null) {
				action = TaskAction.from(actionId);
			}
			actionText = action.getText();
		}
		return actionText;
	}

	public Integer getActionId() {
		return actionId;
	}

	public void setActionId(Integer actionId) {
		this.actionId = actionId;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
}
